import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'

// https://vitejs.dev/config/

import path from "path";

export default defineConfig({
  plugins: [vue()],
  server: {
    port: 3000,
    hot: true,
    proxy: {
      '/api': {
        // target: 'http://47.122.114.242:8080/',
        target: 'https://sushijie.mynatapp.cc',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, ''),
        // 方便联调查看当前请求头代理地址
        bypass(req, res, option) {
          const proxyUrl = new URL(option.rewrite(req.url) || '', option.target)?.href || '';
          res.setHeader('x-req-proxyURL', proxyUrl)
        }
      },
    },
  },
  css: {
    preprocessorOptions: {
      scss: {
        additionalData: ` @import "./src/style/common.scss";`, // 加载全局样式，使用scss特性
      }
    },
  },
  resolve: {
    alias: {
      '@': path.resolve(__dirname, './src')
    },
  }
})

